

// 班尼特白字 191.16+674.33 1.39  =  1203.0311    1202.35
// 九条白字  195.41 509.61   0.8592 =  605.753184  606.3
// 1808.784

let baseData = {};
// 伤害值区间
// 攻击力 hp区间
baseData.baseHp = 14000;
baseData.fixHp = 4780;
baseData.hpRate = 46.6 + 20;  

baseData.baseAtk = 950;
baseData.fixAtk = 311;
baseData.atkRate = 46.6 + 49.6;  
baseData.Rate = 30;  // 技能倍率
// 伤害值增加
baseData.dmgZhiAdd = 0;  // 伤害值增加

// 增伤区间
baseData.dmgRate = 46.6 + 15 + 35 + 40;

// 双爆区间
baseData.crRate = 80;
baseData.crSlike = 160;

// 反应倍率
baseData.reaRate = 1.5    // 1.5 // 2

// 精通增伤
baseData.rea = 115    // 精通
baseData.reaDmgAdd = 0   // 魔女4  莫娜1命等等

// 抗性区间
baseData.Resistance = 10;

// 防御区间(等级压制)
baseData.ylv = 90
baseData.elv = 90
baseData.rlv = 0

let ret = calcLastDmg(baseData)

console.log(JSON.stringify(ret));

let addZhi = [
    {atkRate:5.8},
    {rea:23},
    {crRate:3.9},
    {crSlike:7.8},
    {dmgRate:5.8},
    {dmgZhiAdd:500},
    {fixAtk:50},
    {Resistance:-15},
    {rlv:15},
    {fixAtk: 1110, atkRate: 60, dmgRate: 32 }, //9 班尼  2.01
    {atkRate: 40, dmgRate: 32 + 50, Resistance:-40, rea: 200 }, //10 万叶 2.021  2.521
    {dmgRate: 25, Resistance:-15, dmgZhiAdd:4000*12 }, //11 申鹤 2.18
    {atkRate: 48, dmgRate: 20, Resistance:-40, rea: 360 }, //12 砂糖  2.36
    {atkRate: 20, dmgRate: 20, dmgZhiAdd:1800*30 }, //13 云堇  2.07
    {atkRate: 48, reaDmgAdd: 15, dmgRate:60, crRate: 15}, //14 莫娜  1.8836
    {fixAtk: 790, crSlike: 60}, //15 九条  1.65
    {atkRate: 50, crSlike: 40}, //16 五郎  1.3894
]

addZhi = addZhi.map((item, n) => {
    let tmpRet = calcLastDmg(objValueAdd([baseData, item]))
    console.log("\n");
    console.log(n, JSON.stringify(tmpRet), "ts:" + (tmpRet.qwRet / ret.qwRet) );
    return {tmpRet, n}
})

addZhi.sort((a, b) => b.tmpRet.qwRet - a.tmpRet.qwRet)

console.log(addZhi[0]);


function calcLastDmg(props) {
    let { 
        baseAtk,
        fixAtk,
        atkRate,
        Rate,
        dmgZhiAdd,
        dmgRate,
        crRate,
        crSlike,
        reaRate,
        rea,
        reaDmgAdd,
        Resistance,
        ylv,
        elv,
        rlv
    } = props;
    let dmgZhiCalcRet = (dmgZhiCalc({baseAtk,atkRate,fixAtk,Rate,dmgZhiAdd}));
    let {dmgZhi, attack} = dmgZhiCalcRet;
    let dmgRateCalcRet = (dmgRateCalc({dmgRate}));
    let crRateCalcRet = (crRateCalc({crRate, crSlike}));
    let {bj, qw} = crRateCalcRet
    let reaDmgCalcRet = (reaDmgCalc({rea, reaDmgAdd}));
    if(reaRate!= 1.5 && reaRate!=2) {
        reaDmgCalcRet = 1;
        reaRate = 1;
    }
    let reduceResistanceKRet = (reduceResistanceK(Resistance));
    let lvSuppressKRet = lvSuppressK(ylv, elv, rlv);
    return {
        attack,
        qj : {dmgZhi, attack, dmgRateCalcRet, bj, qw, reaDmgCalcRet, reduceResistanceKRet, lvSuppressKRet},
        qwRet: dmgZhi * dmgRateCalcRet * qw * reaRate * reaDmgCalcRet * reduceResistanceKRet * lvSuppressKRet,
        bjRet: dmgZhi * dmgRateCalcRet * bj * reaRate * reaDmgCalcRet * reduceResistanceKRet * lvSuppressKRet
    } 
}

// 伤害值区间计算
function dmgZhiCalc(props) {
    let {baseAtk,atkRate,fixAtk,Rate,dmgZhiAdd} = props
    
    let attack = (baseAtk * (1 + atkRate / 100) + fixAtk);

    let dmgZhi = attack * Rate + dmgZhiAdd
    return {dmgZhi, attack}
}

// 抗性
function reduceResistanceK (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}

// 防御
function lvSuppressK(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}


// 精通增伤 
function reaDmgCalc(props) {
    let {rea, reaDmgAdd} = props;
    if(rea < 0) { rea = 0 }
    return (278*rea/(rea+1400)) / 100 + reaDmgAdd/100 + 1
}

// 双爆区间
function crRateCalc(props) {
    let {crRate, crSlike} = props;
    if(crRate > 100) {
        crRate = 100;
    }
    if(crRate < 0) {
        crRate = 0
    }
    if(crSlike < 0) {
        crSlike = 0
    }
    return { qw: 1 - (crRate / 100) + (crRate / 100) * (1 + crSlike / 100), bj: 1 + crSlike / 100}
}

// 增伤区间
function dmgRateCalc(props) {
    let {dmgRate} = props;
    return 1 + dmgRate/100
}


function objValueAdd(ObjArr) {
    let ret = {}
    ObjArr.forEach(obj => {
        for (let key in obj) {
            if(!ret.hasOwnProperty(key)) {
                ret[key] = obj[key]
            } else if(/^-?\d+\.?\d*$/.test(obj[key])) {
                ret[key] += obj[key]
            }
        }
    })
    return ret
}